package com.lagou.niancheng.rpc.server;

/**
 * 服务提供者
 *
 * @author 大犬
 * @date 2020/4/30
 */
public class SimpleRpcServerProvider {
    private SimpleRpcConfig simpleRpcConfig;
    private SimpleRpcEndPoint simpleRpcEndPoint;
    private SimpleRpcMethodRegistry simpleRpcMethodRegistry;

    public SimpleRpcServerProvider(SimpleRpcConfig simpleRpcConfig) {
        this.simpleRpcConfig = simpleRpcConfig;
        simpleRpcMethodRegistry = new SimpleRpcMethodRegistry();
        simpleRpcEndPoint = new SimpleRpcEndPoint(simpleRpcMethodRegistry,simpleRpcConfig);
        // 开启服务
        simpleRpcEndPoint.start(simpleRpcConfig.getPort());
    }

    public SimpleRpcServerProvider() {
        this(new SimpleRpcConfig());
    }

    public SimpleRpcServerProvider addProvider(Class providerType, Object instance) {
        simpleRpcMethodRegistry.registerService(providerType, instance);
        return this;
    }

    public SimpleRpcConfig getSimpleRpcConfig() {
        return simpleRpcConfig;
    }
}
